<template>
 <div class="login-container">
  <h1>Login</h1>
  
  <div v-if="status">
    hello, {{ user?.username }}
    <a href="#" @click.prevent="logoutFn">退出登录</a>
  </div>

  <el-form v-else :model="loginForm" label-width="120px">
   <el-form-item label="用户名">
    <el-input v-model="loginForm.username" placeholder="用户名" />
   </el-form-item>
   <el-form-item label="密码">
    <el-input v-model="loginForm.password" placeholder="密码" type="password" show-password/>
   </el-form-item>
   <el-form-item>
    <el-button type="primary" @click="loginFn">登录</el-button>
   </el-form-item>
  </el-form>
 </div>
</template>

<script setup>
import {useUser} from '../hooks/useUser.js';
const {loginForm,user,loginFn,logoutFn,status} = useUser()

</script>

<style lang="scss" scoped>
// .container{
//  width: 80%;
//  height: 100%;
//  background-color: #ccc;
//  margin: 0 auto;
//  padding: 10px 20px;
// }
.login-container{
  margin: 0 auto;
  text-align: center;
}
</style>
  